﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PixelLab.Wpf;
using System.Windows.Media.Animation;
using System.IO;
using DataLayer;

namespace LuanVanProject
{
    /// <summary>
    /// Interaction logic for TextContentView.xaml
    /// </summary>
    public partial class TextContentView : UserControl
    {
        Node parentNode;
        DetailViewContent detailView;

        public DetailViewContent DetailView
        {
            get { return detailView; }
            set { detailView = value; }
        }
        public Node ParentNode
        {
            get { return parentNode; }
            set { parentNode = value; }
        }

        public TextContentView()
        {
            InitializeComponent();
        }
        public TextContentView(string text)
        {
            InitializeComponent();
            MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(text));
            this.MyRTF.Selection.Load(stream, DataFormats.Rtf);
            
        }
        public void SetText(string text)
        {
            MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(text));
            this.MyRTF.Selection.Load(stream, DataFormats.Rtf);
        }
        private void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (this.Parent as ReorderListBox).Items.Remove(this);
            DetailViewContent.ImageTag tag= this.Tag as DetailViewContent.ImageTag;
            DataLayer.Node parentnode=tag.nodeContent.Parent as DataLayer.Node;
            parentnode.ContentList.Remove(tag.nodeContent);
            
        }

        private void dr(object sender, DependencyPropertyChangedEventArgs e)
        {

        }

        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            MessageBox.Show("drop  ");
        }
        private void moveitem_MouseEnter(object sender, MouseEventArgs e)
        {
            ReorderListBox.SetIsDragElement(this, true);
        }

        private void moveitem_MouseLeave(object sender, MouseEventArgs e)
        {
            ReorderListBox.SetIsDragElement(this, false);
        }

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.From = 0;
            da.To = 1;
            da.Duration = new Duration(TimeSpan.FromSeconds(1));
            //MyRect.BeginAnimation(HeightProperty, da);
            DeleteIcon.BeginAnimation(OpacityProperty, da);
            moveitem.BeginAnimation(OpacityProperty, da);
            AddNodeIcon.BeginAnimation(OpacityProperty, da);
       
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.From = 1;
            da.To = 0;
            da.Duration = new Duration(TimeSpan.FromSeconds(1));

            DeleteIcon.BeginAnimation(OpacityProperty, da);
            moveitem.BeginAnimation(OpacityProperty, da);
            AddNodeIcon.BeginAnimation(OpacityProperty, da);
        }

        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void MyGrid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("hello");
        }

        private void AddNodeIcon_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Node node = new Node();
            node.AddContent((this.Tag as DetailViewContent.ImageTag).nodeContent);
            parentNode.AddNode(node);
            NewTreeNode newTreeNode = new NewTreeNode();
            newTreeNode.ShowDialog();
            if (newTreeNode.result != null)
            {
                node.Name = newTreeNode.result;
                parentNode.ContentList.Remove((this.Tag as DetailViewContent.ImageTag).nodeContent);
                App.Synchronize();
                detailView.SetContain(node);
            }
        }
    }
}
